package jdmx.framework.ui;

import jdmx.framework.common.Envelope;
import jdmx.framework.common.interfaces.Proxy;
import jdmx.framework.common.serialization.Serializer;

public class ProxyLocalSerialized implements Proxy {
	private byte[] execute (byte[] serializedRequest) {
		Envelope deRequest = Serializer.deserializeFromByteArray(serializedRequest);
		Envelope deResponse = UIContext.facade.execute(deRequest);
		byte[] serializedResponse =  Serializer.serializeToByteArray(deResponse);
		return serializedResponse;
	}

	public void init() {
		if (UIContext.facade != null) UIContext.facade.init();
	}
	
	public Envelope run(Envelope dataEnvelope) {
		return null;
	}

	public Envelope execute(Envelope dataEnvelope) {
		byte[] serializedRequest = Serializer.serializeToByteArray(dataEnvelope);
		byte[] serializedResponse = execute(serializedRequest);
		return Serializer.deserializeFromByteArray(serializedResponse); 
	}

}
